<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class User {
            constructor(role, pages) {
                this.role = role
                this.pages = pages
            }

            static UserFactory(role) {
                switch (role) {
                    case "superadmin":
                        return new User("superadmin", ["home", "user-manage", "right-manage", "news-manage"])
                        break;
                    case "admin":
                        return new User("admin", ["home", "user-manage", "news-manage"])
                        break;
                    case "editor":
                        return new User("editor", ["home", "news-manage"])
                        break;
                    default:
                        throw new Error("参数错误")
                }
            }
        }


        var user = User.UserFactory("superadmin")
    </script>
</body>

</html>